import router from './router'
import NProgress from 'nprogress' // 引入一份进度条插件
import 'nprogress/nprogress.css' // 引入进度条样式
import VueCookies from 'vue-cookies'
import Vue from 'vue'
Vue.use(VueCookies)
const whiteList = ['/login', '/404']
router.beforeEach((to, from, next) => {
  NProgress.start()
  // 当存在cookies
  if (VueCookies.get('admin_id')) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    // 不存在cookie,判断是否在白名单之中
    if (whiteList.indexOf(to.path) > -1) {
      next()
    } else {
      next('/login') // 否则登录
    }
  }
  NProgress.done()
})
router.afterEach(() => {
  NProgress.done()
})
